/**
* erp路由处理
* 1. 弹出顶层界面提示填写erp
* 2. 自动处理erp请求
* 3. 手动处理erp请求（没有维护，可能会弃用）
*/
window.posterp = async function() {
 // 使用示例
 var access_token = getCookie('access_token');
 console.log(access_token);
 //记忆化存储erp，方便填写

 const par = {
   "ServiceOpportunityID": "",
   "ContactID": "",
   "ContactText": "",
   "CustomerClueID": "",
   "saleActivityCustomer": "",
   "saleActivityCustomerName": "",
   "JoinUserList": "",
   "MainBodyType": null,
   "WorkType": 7,
   "StatusID": "",
   "WorkLocation": 5,
   "WorkingHours": 8,
   "NeedAsyncWorkWechatSchedule": false,
   "LeaveType": 1,
   "date": "2024-05-28T00:00:00.000Z",
   "startTime": "2024-05-28 09:00",
   "endTime": "2024-05-28 18:30",
   "time": [
     "09:00",
     "18:30"
   ],
   "customer": "8a79193e-7ffb-e911-80f3-a2d3a0e0fa10",
   "CustomerName": "武汉众邦银行股份有限公司",
   "ProjectID": "c97e680c-59f5-421f-ba6d-575e3454f647",
   "DevelopmentType": 2,
   "EventType": 1,
   "SubjectID": "",
   "Subject": "05-27-dsadasda",
   "SubjectName": "",
   "ProductID": "F1F5ACF5-637A-4CC0-8AF4-AE2CF2A518DA",
   "ProductName": "",
   "TrainingProjectID": "",
   "BusinessKindID": "113B2E2E-9EE4-43DA-B257-F6F56E95387F",
   "IsDuringAllDay": true,
   "Body": "05-27",
   "BusinessTrip_Location": "",
   "ReimburseAmount": 0,
   "IsBusinessTrip": false,
   "HasMealAllowance": false,
   "ReimList": [],
   "PpmAppointmentInfo": {},
   "ProjectName": "",
   "ProductDevelopmentInfo": {
     "DevelopmentType": 2,
     "BusinessKindID": "113B2E2E-9EE4-43DA-B257-F6F56E95387F",
     "ProductID": "F1F5ACF5-637A-4CC0-8AF4-AE2CF2A518DA",
     "ProjectID": "c97e680c-59f5-421f-ba6d-575e3454f647"
   }
 }
 // 修改事件
 const now = new Date()
 // const formattedDate = currentDate.toISOString().split('T')[0] + 'T00:00:00.000Z';

 // 获取年、月、日
 const year = now.getFullYear();
 const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1
 const day = String(now.getDate()).padStart(2, '0'); // 日期不足两位前补0

 // 格式化日期
 const formattedDate = `${year}-${month}-${day}`;

 par.date = formattedDate + 'T00:00:00.000Z'
 par.startTime = formattedDate + ' 09:00'
 par.endTime = formattedDate + ' 18:30'
 par.Body = formattedDate + '<br>\n详情请访问：http://10.10.41.235:8001/'
 par.Subject = formattedDate + '日报'


 url = 'https://erpgateway.cwoa.net:10240/net/api/AppointmentNew/SaveAppointment?t=1716962433530&customerActivityID=undefined'

 head = {
   'Accept': 'application/json, text/plain, */*',
   'Accept-Encoding': 'gzip, deflate, br, zstd',
   'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6',
   'Authorization': 'Bearer ' + access_token,
   'Cache-Control': 'no-cache',
   'Connection': 'keep-alive',
   'Content-Length': '1181', // 需要替换为实际的JSON数据长度
   'Content-Type': 'application/json',
   'DNT': '1',
   'Host': 'erpgateway.cwoa.net:10240',
   'Origin': 'https://erpnew.cwoa.net',
   'Pragma': 'no-cache',
   'Referer': 'https://erpnew.cwoa.net/',
   'Sec-Fetch-Dest': 'empty',
   'Sec-Fetch-Mode': 'cors',
   'Sec-Fetch-Site': 'same-site',
   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0',
   'sec-ch-ua': '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
   'sec-ch-ua-mobile': '?0',
   'sec-ch-ua-platform': '"Windows"'
 }

  // 可以用.then处理返回的promise链，也可以使用async await处理
  let res
  return fetchData(url, head, par)

}